export default {
    request(url, data, method) {
        if (data == null || data == '') {
            data = {}
        }
        uni.showLoading({
            title: '加载中'
        });
        let baseUrl = 'http://localhost:1234/'//这里用的uni免费的云函数URL
        return new Promise((resolve, reject) => {//使用Promise返回数据
            uni.request({
                url: baseUrl + url,
                method: method,
                data: data,
                header: {
                    "Content-Type": "application/x-www-form-urlencoded"
                },
                success(res) {
                    uni.hideLoading();
                    resolve(res.data)
                },
                fail(err) {
                    reject(err)
                }
            })
        })
    },
    requestForForm(url, data, method) {
        uni.showLoading({
            title: '加载中'
        });
        let baseUrl = 'http://localhost:1234/'//这里用的uni免费的云函数URL
        return new Promise((resolve, reject) => {//使用Promise返回数据
            uni.request({
                url: baseUrl + url,
                method: method,
                data: data,
                header: {
                    "Content-Type": "multipart/form-data",
                },
                success(res) {
                    uni.hideLoading();
                    resolve(res.data)
                },
                fail(err) {
                    reject(err)
                }
            })
        })
    },
    requestForJSON(url, data, method) {
        uni.showLoading({
            title: '加载中'
        });
        let baseUrl = 'http://localhost:1234/'//这里用的uni免费的云函数URL
        return new Promise((resolve, reject) => {//使用Promise返回数据
            uni.request({
                url: baseUrl + url,
                method: method,
                data: data,
                header: {
                    "Content-Type": "application/json;charset=UTF-8"
                },
                success(res) {
                    uni.hideLoading();
                    resolve(res.data)
                },
                fail(err) {
                    reject(err)
                }
            })
        })
    }
}